package com.controller;

import com.pojo.Msg;
import com.pojo.OrderItem;
import com.service.OrderItemsService;
import com.shiro.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RequiresPermissions(value={"orderTable:*"})
@Controller
@ResponseBody
public class OrderItemsController extends BaseController {

    @Autowired
    private OrderItemsService orderItemsService;


    //删除 订单条目
    @RequestMapping(value = "/orderitems/{oiId}", method = RequestMethod.DELETE)
    public Msg deleteOrderItemsByOiId(@PathVariable("oiId") String oiId){
        Integer id = Integer.parseInt(oiId);
        orderItemsService.deleteOrderItems(id);
        Msg msg  = Msg.success();
        return msg;
    }

    //修改更新商品条目
    @RequestMapping(value = "/orderitems/{oiId}", method = RequestMethod.PUT)
    public Msg updateOrderItems(@RequestBody OrderItem orderItem){
        orderItemsService.updateOrderItems(orderItem);
        return Msg.success();
    }

//    //插入商品条目，不在订单控制器中写, 当完成点餐的时候触发,正式下单
    @RequestMapping(value = "/orderitem/insert", method = RequestMethod.POST)
    public Msg insertOrderItems(@RequestBody List<OrderItem> orderItemList, @RequestParam("oid") Integer oid){
        orderItemsService.insertOrderItemsAll(oid, orderItemList);
        return Msg.success();
    }


}
